package com.moorror.cola.strategy.plugin.view.window;

import com.alibaba.cola.extension.ExtensionRepository;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.moorror.cola.strategy.plugin.view.component.CSPanel;
import org.jetbrains.annotations.NotNull;

/**
 * @Author jiyanghuang
 * @Date 2022/3/13 11:53 PM
 */
public class CSPluginWindowFactory implements ToolWindowFactory {

    public static final String TOOL_ID = "ColaStrategy";
    public static ToolWindow toolWindow;
    public static Project project;

    public static ExtensionRepository extensionRepository = new ExtensionRepository();

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        CSPanel previewPanel = new CSPanel(project, toolWindow);
//        ContentFactory contentFactory = ContentFactory.getInstance();
        ContentFactory contentFactory = ApplicationManager.getApplication().getService(ContentFactory.class);
        // 其实往里添加 diplayName 时，它会像类似于 tab 的效果，如果没有名称就不会展示了
        Content content = contentFactory.createContent(previewPanel, "", false);
        toolWindow.getContentManager().addContent(content);
    }
}
